package com.neuedu.io;

import java.io.*;

public class StreamDemo {
    public static void main(String[] args) {
        //0000 0000  1111 1111   0 - 255    0 - 65535
       File  file = new File("D:/1.gif");
       File file2 = new File("D:/2.gif");
       if(!file2.exists()) {
           try {
               file2.createNewFile();
           } catch (IOException e) {
               throw new RuntimeException(e);
           }
       }
        InputStream  in;
        OutputStream  os;
        try {
            in = new FileInputStream(file);
            os = new FileOutputStream(file2);
//            int  ch = in.read();
            int ch = 0;
            int count = 0;
            while( (ch = in.read()) !=-1){
                System.out.print((char)ch);
                count++;
                if(count >=50000)
                    break;
                os.write(ch);
            }
            System.out.println(count);
            in.close();
            os.close();

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }catch (IOException  e){
            throw new RuntimeException(e);
        }
    }
}
